<div class="fsh-pop">
    <input type="password" style="display: none"/>
    <div id="add_form" class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>任务名称</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" placeholder="制作一个杯子模型" class="layui-input" id="parentTitle"
                       readonly>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>效果图</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <img src="./res/images/index-header.jpg" class="pic">
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label"><i>*</i>课程视频</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <img src="./res/images/index-header.jpg" class="pic">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">课程作业</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="自己制作一个杯子模型" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">附件</label>
            <div class="layui-input-block">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-sm"> 下载</button>
                </div>
            </div>
        </div>
    </div>

</div>
<style>
    .pic {
        width: 200px;
        height: 100px;
        margin-top: 10px;
    }
</style>
<script type="text/javascript">

    layui.use(['upload', 'form'], function () {
        var upload = layui.upload;
        var form = layui.form;

        $("#parentTitle").click(function () {
            showDialog({
                title: '选择父级菜单'
                , template: 'menu'
                , width: 400
                , height: 600
                , yes: function (index, layero) {
                    var res = callbackdata();
                    layer.close(index);
                    $("#parentTitle").val(res.title);
                    $("#parent_id").val(res.key);
                }

            });

        });
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload_header'
            , url: context + '/api/fileupload/add'
            , field: 'attach'
            , done: function (res) {
                //如果上传失败
                if (res.success) {
                    // $('#demo1').attr('src', res.link);
                    $('#resUrl').val(res.link);
                } else {
                    layui.layer.msg('上传失败');
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    });

</script>
